package m2acsis.algebre.helpers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class TypeHelper {

	public static boolean isSameType(Object obj, Class<?> type){
		
		if(obj != null){
			
			if(obj.getClass().isArray()){
				
				List<Object> objects = new ArrayList<Object>(Arrays.asList((Object[]) obj));
				
				if(objects.size() > 0){
					
					for(Object o:objects){
						if(o == null || !isSameType(o, type)){
							return false;
						}
					}
				}
				
				return true;
			}
			
			return obj.getClass().equals(type);
		}
		
		return false;
	}
	
	public static boolean isNotNull(Object obj){
		
		if(obj != null){
			
			if(obj.getClass().isArray()){
				
				List<Object> objects = new ArrayList<Object>(Arrays.asList((Object[]) obj));
				for(Object o:objects){
					if(o == null ||	!isNotNull(o))
						return false;
				}
			}

			return true;
		}
		
		return false;
	}
}
